package com.sjksy.demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sjksy.demo.domain.Spots;
import com.sjksy.demo.dto.travel_route.SpotsDto;
import com.sjksy.demo.msmapper.travel_route.TravelRouteMsMapper;
import com.sjksy.demo.service.SpotsService;
import com.sjksy.demo.mapper.SpotsMapper;
import com.sjksy.demo.vo.travel_route.SpotsVo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author guyueyuan
* @description 针对表【spots】的数据库操作Service实现
* @createDate 2024-12-11 15:37:03
*/
@Service
public class SpotsServiceImpl extends ServiceImpl<SpotsMapper, Spots>
    implements SpotsService{

    @Resource
    SpotsMapper spotsMapper;
    @Resource
    TravelRouteMsMapper travelRouteMsMapper;

    @Override
    public List<SpotsVo> getAllSpots() {
        List<Spots> spots = spotsMapper.selectList(null);
        List<SpotsVo> spotsVos=new ArrayList<>();
        spots.forEach((spot)->{
            spotsVos.add(travelRouteMsMapper.dtoToSpotsVo(travelRouteMsMapper.spotsToSpotsDto(spot)));
        });
        return spotsVos;
    }

    @Override
    public boolean postSpots(SpotsVo spotsVo) {
        int insert = spotsMapper.insert(travelRouteMsMapper.dtoToSpots(travelRouteMsMapper.voToSpotsDto(spotsVo)));
        return insert>0;
    }
}




